<?php
declare (strict_types=1);

namespace app\callback\controller;

use app\BaseController;
use app\Request;
use think\facade\Log;
use think\response\Json;

/**
 * 阿旗数据平台
 */
class AqiInfo extends BaseController
{

    public function getCodeAfterSubscribe(Request $request): Json
    {
        $postdata = file_get_contents("php://input");
        if (!$postdata) {
            $postdata = $request->all();
        }
        Log::write(json_encode($postdata), '阿旗数据平台');
        //接收参数
        $mac_id = $request->param('vmid', '');
        //$user_id = $request->param('exUid',0);
        $type = $request->param('type', 0);
        //获取配置缓存
        $sys_config = config('sys_config.WsOfficialAccount');
        //查询用户微信信息
        $user_id = 27;
        $where = ['user_id' => $user_id, 'appid' => $sys_config['appid']];
        $userWechat = UserWechat::findOne($where, 'openid,subscribe');
        $params = [
            'user_id' => $userWechat['openid'],//自营公众号open_id
            'mac_id' => $mac_id, //写入rabit mq 队列
            'type' => $type
        ];
        (new OutbagService())->updateSafeCode($params);
        if (!empty($postdata)) {
            return json(['code' => 200]);
        }
    }


}
